#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve() {
    int n, k;
    cin >> n >> k;
    priority_queue<int> pq;
    int ans = 0;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) {
        pq.push(a[i]);
        if((n - k - i) % (k + 1) == 0) {
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;
}

signed main() {
    int t = 1;
    cin >> t;
    while(t--) solve();
    return 0;
}